<html>
<head>
<title>${place.world.name} : ${place.name}</title>
<style>
table, body {
	font: 15px 'Arial';
}
a {
	text-decoration: none;
}
.error {
	border: 1px solid red;
	background-color: #FFCCCC;
	color: red;
	padding: 2px;
	margin: 5px;
}
.cube {
	text-align: center;
	width: 20px;
	height: 20px;
}
.ground {
	background-color: #CCEE88;
}
.air {
	background-color: #EEEEFF;
}
.water {
	background-color: #CCCCFF;
}
.fromCube {
	border: 2px solid green;
}
.pathCube {
	border: 2px solid orange;
}
.toCube {
	border: 2px solid red;
}
</style>
</head>
<body>
	<g:if test="${flash.message}">
		<div class="message">${flash.message}</div>
	</g:if>
	<g:if test="${flash.error}">
		<div class="error">${flash.error}</div>
	</g:if>

	<g:set var="from" value="${cubes.first()}" />
	<g:set var="to" value="${cubes.last()}" />
	
	<g:each var="z" in="${(to.z)..(from.z)}">
		<table border="1">
			<g:each var="y" in="${(from.y)..(to.y)}">
				<tr>
				<g:each var="x" in="${(from.x)..(to.x)}">
					<g:set var="n" value="${z*(to.y+1)*(to.x+1) + y*(to.x+1) + x}" />
					<g:set var="cube" value="${cubes[n]}" />
					<%
					def css = ''
					if (pathCubes.contains(cube)) css = 'pathCube'
					if (cube == toCube) css = 'toCube'
					if (cube == fromCube) css = 'fromCube'
					%>
					<td class="cube ${cube.type.name} ${css}" title="${cube}">
						<g:if test="${cube.unit}">
							<g:if test="${cube == fromCube && cube != toCube}">
								<g:link action="place" id="${place.id}" style="color:#${cube.unit?.team?.color}" title="cancel">${cube.unit?.type?.name?.charAt(0)}</g:link>
							</g:if>
							<g:else>
								<g:link action="selectUnit" id="${cube.unit.id}" params="${[place:place.id]}" style="color:#${cube.unit?.team?.color}" title="${cube.unit?.type?.name}">${cube.unit?.type?.name?.charAt(0)}</g:link>
							</g:else>
						</g:if>

						
						<g:if test="${adjCubesDir[(cube.id)] && cube != fromCube && (pathCubes.size() <= unit.type.move || cube == beforeToCube)}">
							<g:link action="appendCubeForMove" id="${cube.id}" params="${[place:place.id, unit:unit?.id, path:params.path]}" style="color:#${fromCube?.unit?.team?.color}" title="go to ${adjCubesDir[(cube.id)].name().toLowerCase()}">${adjCubesDir[(cube.id)].arrow}</g:link>
						</g:if>
						
						<g:if test="${cube == toCube && cube != fromCube}">
							<g:link action="moveUnit" id="${unit.id}" params="${[place:place.id, unit:unit?.id, path:params.path]}" style="color:#${fromCube?.unit?.team?.color}" title="move">${unit.type.move + 1 - pathCubes.size()}</g:link>
						</g:if>
					</td>
				</g:each>
				</tr>
			</g:each>
		</table>
		<br/>
	</g:each>

	<g:if test="${fromCube}">
		<div>From cube : ${fromCube}</div>
	</g:if>
	<g:if test="${toCube}">
		<div>To cube : ${toCube}</div>
		<div>Adjacent cubes : ${adjacentCubes}</div>
	</g:if>
	<g:if test="${unit}">
		<div>Selected unit : ${unit}</div>
	</g:if>
	<g:if test="${params.path}">
		<div>Path : ${params.path}</div>
	</g:if>

</body>
</html>